﻿using System;

namespace WhenNothingToDo
{
    public class Fighter
    {
        public Fighter(String name) 
        {
            this.Name = name;
            this.Strength = 10;
            this.Health = 100;
            this.Speed = 0.5;
        }

        public String Name
        { get; private set; }

        public double MaxHealth
        { get; private set; }

        public double Health
        { get; private set; }

        public double Strength
        { get; private set; }

        public double Speed
        { get; private set; }

        public double Hit() 
        {
            Console.WriteLine("{0} hit {1}", this.Name, this.Speed * this.Strength);
            return this.Speed * this.Strength;
        }

        public void Hitted(double hit) 
        {
            if (this.block()) 
            {
                hit /= 2;
            }
            this.Health -= hit;
            this.Health = this.Health < 0 ? 0 : this.Health;
            Console.WriteLine("{0} was beaten and his health  {1}", this.Name, this.Health);
            if (this.Health <= 0) 
            {
                this.lose();
            }
        }

        public bool isAlive()
        {
            return this.Health > 0;
        }

        public void TrainSpeed() 
        {
            Console.WriteLine("{0} trained speed", this.Name);
            this.Speed += this.Speed * 0.1;
        }

        public void TrainStrength() 
        {
            Console.WriteLine("{0} trained strength", this.Name);
            this.Strength += this.Strength * 0.1;
        }

        private void lose() 
        {
            Console.WriteLine("{0} is lost", this.Name);
        }

        private bool block() 
        {
            var random = new Random();

            if (random.NextDouble() > 0.6)
            {
                Console.WriteLine("{0} blocked", this.Name);
            }

            return random.NextDouble() > 0.83;  
        }
    }
}
